#include <iostream>
#include <vector>
#include <algorithm>
#include <sys/time.h>

using namespace std;

void setZeroes(vector<vector<int> > &matrix) 
{
  
  const int nCol= matrix.at(0).size();
  const int nRow = matrix.size();
  if(nRow<1)
    return;
  vector<bool>  indCol(nCol,false);
  for( int i=0;i<matrix.size();++i )
  {
    bool hasZero = false;

    for(int j=0;j<nCol;++j)
    {
      if( matrix.at(i).at(j)==0 ) 
      {
        indCol[j]=true ;
        hasZero = true;
      }
    }

    if(hasZero)
    {
      std::fill( matrix.at(i).begin(), matrix.at(i).end(), 0 );
    }


  }

  for(int i=0;i<matrix.size();++i  )
  {
    for(int j=0;j<nCol;++j )
    {
      if(indCol[j])
      {
        matrix.at(i).at(j)=0;
      }

    }
  }




}



int main(int argc,char *argv[])
{

  vector< vector<int> > matrix;
  //vector<int> a(3,1);
  int r=300;
  //while(r--)
  {
  matrix.push_back( vector<int>(1,0));
  //matrix.push_back( vector<int>(3000,1));
  //matrix.push_back( vector<int>(3000,1));
  }
 // matrix.at(10).at(10)=0;
  cout<<"-------before-----------"<<endl;
  for( int i=0;i<matrix.size();++i )
  {
    for(int j=0;j<matrix.at(0).size();++j)
    {
      cout<<matrix.at(i).at(j)<<","; 
    }
    cout<<endl;
  }


  struct  timeval    tv1,tv2;
  struct  timezone   tz;
  int time1 = gettimeofday(&tv1,&tz);

  //func();
  setZeroes(matrix);

  int time2 = gettimeofday(&tv2,&tz);
  cout << "time consuming:" << tv2.tv_usec - tv1.tv_usec <<"us"<< endl;
  cout<<"-------after-----------"<<endl;

  for( int i=0;i<matrix.size();++i )
  {
    for(int j=0;j<matrix.at(0).size();++j)
    {
      cout<<matrix.at(i).at(j)<<","; 
    }
    cout<<endl;
  }


  return 0;
}
